package main

import (
	"fmt"
	"git.inke.cn/baiying/slove/server/silian_server_sdk/util/define"
	"github.com/jinzhu/now"
	"testing"
	"time"
)

func main() {
	Now()
}

func Now() {
	fmt.Println(time.Now().UnixNano()/1e6)
}

//时间的加减方式
func TimeAdd() {
	newTime := time.Unix(1656604799, 0)
	comTime := time.Date(newTime.Year(), newTime.Month(), newTime.Day()+1, 0, 0, 0, 0, newTime.Location())               //这种方式是有问题的，闰年这些无法自动识别
	comTime = time.Date(newTime.Year(), newTime.Month(), newTime.Day(), 0, 0, 0, 0, newTime.Location()).AddDate(0, 0, 1) //改成这种方式
	comTime = now.BeginningOfDay().AddDate(0, 0, 1)
	fmt.Println(comTime.Unix())
}

func Test2(t *testing.T) {
	fmt.Println(now.BeginningOfDay().Format("2006-01-02 15:04:05"),
		now.EndOfDay().Format("2006-01-02 15:04:05"))
}

func Ticker() {

}

//给定一个周一的时间，获取上周的7天从开始到结尾，并且拆分每天的开始和结尾
func testFromAndTo() {
	to := now.BeginningOfDay()   //今天凌晨
	from := to.AddDate(0, 0, -7) //七天前
	fmt.Println(to.Format(define.FormatStr), from.Format(define.FormatStr))

	for from.Before(to) {
		startTime := from                //查询开始时间
		endTime := from.AddDate(0, 0, 1) //查询结束时间
		fmt.Println(fmt.Sprintf("开始时间：%v,结束时间：%v", startTime.Format(define.FormatStr), endTime.Format(define.FormatStr)))
		from = from.AddDate(0, 0, 1)
	}
}
